package com.hmz.backend.controller.chat;

import cn.hutool.json.JSONObject;
import com.hmz.backend.mapper.ChatRoomMapper;
import com.hmz.backend.service.chat.ChatRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

@RestController
public class ChatRoomController {
    @Autowired
    ChatRoomService chatRoomService;

    /**
     * 创建聊天室
     * @param data
     * @return
     */
    @PostMapping("/createChatRoom")
    public JSONObject createChatRoom(@RequestBody JSONObject data){
        return chatRoomService.createChatRoom(data);
    }

    /**
     * 创建获取指定Id下的的所有非好友聊天室
     * @param userId
     * @return
     */
    @GetMapping("/getMyChatRoomList")
    public JSONObject getMyChatRoomList(@RequestParam int userId){
         return chatRoomService.getMyChatRoomList(userId);
    }

    /**
     * 根据用户输出的关键字模糊搜索关键字
     * @param chatRoomName
     * @param userId
     * @return
     */
    @GetMapping("/searchChatRoom")
    public JSONObject searchChatRoom(@RequestParam String chatRoomName,@RequestParam int userId){
        return chatRoomService.searchChatRoom(chatRoomName,userId);
    }

    /**
     * 加入聊天室
     * @param data
     * @return
     */
    @PostMapping("/joinChatRoom")
    public JSONObject joinChatRoom(@RequestBody JSONObject data){
        return chatRoomService.joinChatRoom(data);
    }

    /**
     * 获取指定聊天室下的所有用户列表
     * @param chatRoomId
     * @return
     */
    @GetMapping("/getChatRoomUserList")
    public JSONObject getChatRoomUserList(@RequestParam int chatRoomId){
        return chatRoomService.getChatRoomUserList(chatRoomId);
    }

    /**
     * 退出聊天室
     * @param data
     * @return
     */
    @PostMapping("/deleteMyChatRoom")
    public JSONObject deleteMychatRoom(@RequestBody JSONObject data){
        return chatRoomService.deleteMychatRoom(data);
    }
}
